package Ex01.Stage002;

import java.util.Scanner;

/**
 * @author 73594
 */
public class Pay {
    public Goods[] goods = new Goods[10];
    public void setData(Goods[] goods){
        this.goods = goods;
    }
    public void calcPrice() {
        String custName = "";; // 客户名字
        int goodsNo = 2; // 商品编号
        double price = 0; // 商品价格
        String name = "";
        int count; // 购入数量
        String choice;
        String goodsList = ""; // 购物清单
        double total = 0; // 购物总金额
        double discount = 0.8;//折扣
        double finalPay = 0; // 打折后需付款
        double payment; // 实际交费金额
        System.out.println("购物 > 购物结算\n\n");
        // 打印产品清单
        System.out.println("*************************************");
        System.out.println("请选择购买的商品编号：");
//        for (int i = 0, p = 0; i < goods.length && null != goods[i].goodsName; i++) {
//            p++;
//            System.out.println(p + ": " + goods[i].goodsName + "\t");
//        }
        System.out.println("*************************************\n");
        /* 进行购入结算系统 */
        Scanner input = new Scanner(System.in);
            do {
                System.out.print("\t请输入商品编号："); // 数组下标+1即产品编号
                goodsNo = input.nextInt();
                System.out.print("\t请输入数目：");
                count = input.nextInt();

                // 查询单价
                price = goods[goodsNo - 1].goodsPrice;
                name = goods[goodsNo - 1].goodsName;
                total = total + price * count;

                // 连接购物清单
                goodsList = goodsList + "\n" + name + "\t" + "￥" + price + "\t\t" + count + "\t\t" + "￥" + (price * count) + "\t";
                System.out.print("\t是否继续（y/n）");
                choice = input.next();
            } while (choice.equals("y"));

            // 计算消费总金额
            finalPay = total * discount;

            // 打印消费清单
            System.out.println("\n");
            System.out.println("＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊消费清单＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊");
            System.out.println("物品\t\t" + "单价\t\t" + "个数\t\t" + "金额\t");
            System.out.print(goodsList);
            System.out.println("\n折扣：\t" + discount);
            System.out.println("金额总计:\t" + "￥" + finalPay);
            System.out.print("实际交费:\t￥");
            payment = input.nextDouble();
            System.out.println("找钱:\t" + "￥" + (payment - finalPay));
            // 计算获得的积分：
            int score = (int) finalPay / 100 * 3;
            System.out.println("本次购物所获的积分是： " + score);
        }

}

